import java.util.Arrays;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2023-05-24
 * Time: 20:48
 */
public class Main2 {
    public static void main(String[] args) {
        int[][] arr={{1,3,6},{7,9,23}};
        int target=4;
        System.out.println(Arrays.toString(searchNum(arr, target)));
    }
    public static int[] searchNum(int[][] arr,int target){
        
        /*int m=arr.length,n=arr[0].length;
        int row=0,col=n-1;
        while (row<m && col>=0){
            if(arr[row][col]==target){
                return new int[]{row,col};
            }else if(arr[row][col]> target){
                col--;
            }else{
                row++;
            }
        }
        return new int[] {-1,-1};*/
    
        int m=arr.length,n=arr[0].length;
        int left=0,right=m*n-1;
        while (left<=right){
            int mid=left+(right-left)/2;
            int row=mid/n;
            int col=mid%n;
            if(arr[row][col]==target){
                return new int[]{row,col};
            }else if(arr[row][col]<target){
                left=mid+1;
            }else {
                right=mid-1;
            }
        }
        return new int[]{-1,-1};
    }
}
